package niuke;

import java.util.Arrays;

/**
 * Created by asus on 2017/12/2.
 */
public class Permutation {

    public static void main(String[] args) {
        //为了测试函数的简单展示，这儿写死了n=4
        int[] arr={1,2,3,4};
        permutate(arr,0);
    }

    public static void permutate(int[] list, int pointer) {
        if (pointer == list.length) {
            System.out.println(Arrays.toString(list));
            return;
        }
        //不断交换两个数的思想
        for (int i = pointer; i < list.length; i++) {
            int[] permutation = list.clone();
            permutation[pointer] = list[i];
            permutation[i] = list[pointer];
            permutate(permutation, pointer + 1);
        }
    }

}
